<template>
  <div>
    <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
      :default-active="defaultActive" text-color="#fff" unique-opened router>
      <el-menu-item index="/home">
        <el-icon>
          <Menu />
        </el-icon>
        <span>首页</span>
      </el-menu-item>
      <el-sub-menu v-for="item in store.getters.getUser.menus" :index="item.id.toString()" :key="item.id">
        <template #title>
          <el-icon>
            <component :is='item.icon'></component>
          </el-icon>
          <span>{{ item.title }}</span>
        </template>
        <el-menu-item v-for="menu in item.children" :index="menu.url" :key="menu.id">{{
          menu.title
        }}</el-menu-item>
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
let defaultActive = ref('/home')
let store = useStore()
let router = useRouter()
onMounted(() => {
  defaultActive.value = router.path

})

</script>

<style lang="less" scoped>
.el-menu-vertical-demo {
  height: 92vh;
}
</style>